import AppConstants from "../framework/scripts/AppConstants"
import AppUtil from "../framework/scripts/AppUtil"
import TimerMgr from "../framework/scripts/manager/TimerMgr"
import PanelMgr from "../framework/scripts/view/PanelMgr"
import TopBlock from "../framework/scripts/view/TopBlock"
import UIBase from "../framework/scripts/view/UIBase"
import UIMgr from "../framework/scripts/view/UIMgr"
import PanelGreen from "./PanelGreen"
import PanelStateMachine from "./PanelStateMachine"
import PanelYellow from "./PanelYellow"
import UIBag from "./UIBag"
import UISdk from "./UISdk"
import Tip from "./core/Tip"
import Wait from "./core/Wait"


export default class UIMain extends UIBase {
    public skinPath: string = 'UIMain'
    public uiShowStyle: number = AppConstants.uiShowStyle.FadeIn


    protected onButtonClick(button: cc.Node) {
        switch (button.name) {
            case 'BtnUIBag':
                UIMgr.open(UIBag)
                break

            case 'BtnNewSpriteNode':
                TopBlock.show()

                const tmpNode = new cc.Node('tmpNode')
                tmpNode.parent = this.skin
                tmpNode.zIndex = 100

                const sprite1 = AppUtil.newSpriteNode()
                sprite1.parent = tmpNode
                sprite1.x = -150

                const sprite2 = AppUtil.newSpriteNode()
                sprite2.parent = tmpNode
                sprite2.color = cc.Color.GREEN

                const sprite3 = cc.instantiate(sprite1)
                sprite3.parent = tmpNode
                sprite3.x = 150
                sprite3.color = cc.Color.RED

                TimerMgr.inst.add(3000, () => {
                    TopBlock.hide()
                    tmpNode.destroy()
                })
                break

            case 'BtnPanelYellow':
                PanelMgr.show(PanelYellow)
                break
            case 'BtnPanelGreen':
                PanelMgr.show(PanelGreen)
                break

            case 'BtnTip':
                Tip.show('哈哈哈哈哈哈哈哈哈哈')
                break
            case 'BtnWait':
                Wait.show()
                TimerMgr.inst.add(3000, () => Wait.hide())
                break

            case 'BtnStateMachine':
                PanelMgr.show(PanelStateMachine)
                break

            case 'BtnSdk':
                UIMgr.open(UISdk)
                break
        }
    }
}
